package com.etime.shuhuiyuan.controllers.saler;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.common.BaseMessage;
import com.etime.shuhuiyuan.common.ListMessage;
import com.etime.shuhuiyuan.common.PageMessage;
import com.etime.shuhuiyuan.common.PojoMessage;
import com.etime.shuhuiyuan.pojo.Saler;
import com.etime.shuhuiyuan.services.department.interfaces.DepartmentService;
import com.etime.shuhuiyuan.services.saler.interfaces.SalerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * department示例的controller控制层
 */
@Api(tags = "saler案例接口")
@RestController
@RequestMapping("/saler")
public class SalerController {

    @Autowired
    private SalerService salerService;


    @ApiOperation("添加saler案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="salerid",value = "自增长主键，不传递"),
            @ApiImplicitParam(name="salerdeptid",value="传递字符串"),
            @ApiImplicitParam(name="salercode",value = "传递销售人员推荐码"),
            @ApiImplicitParam(name="salerbankname",value="传递开户银行"),
            @ApiImplicitParam(name="salerbanknum",value = "传递银行卡号"),
            @ApiImplicitParam(name="salerauditstate",value = "传递数字 0表示异常 1表示正常"),
            @ApiImplicitParam(name="salerauditdesc",value = "传递审核描述"),
            @ApiImplicitParam(name="salertakepoint",value = "传递销售提成")
    })
    @GetMapping("/insert")
    public BaseMessage insertSaler(Saler saler){
        BaseMessage msg = new BaseMessage();
        int rtn = salerService.insertSaler(saler);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存成功");
        }else{
            msg.setMsg("保存失败");
        }
        return msg;
    }

    @ApiOperation("修改案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="salerid",value = "自增长主键，不传递"),
            @ApiImplicitParam(name="salerdeptid",value="传递字符串"),
            @ApiImplicitParam(name="salercode",value = "传递销售人员推荐码"),
            @ApiImplicitParam(name="salerbankname",value="传递开户银行"),
            @ApiImplicitParam(name="salerbanknum",value = "传递银行卡号"),
            @ApiImplicitParam(name="salerauditstate",value = "传递数字 0表示异常 1表示正常"),
            @ApiImplicitParam(name="salerauditdesc",value = "传递审核描述"),
            @ApiImplicitParam(name="salertakepoint",value = "传递销售提成")
    })
    @GetMapping("/update")
    public BaseMessage updateDepartment(Saler saler){
        BaseMessage msg = new BaseMessage();
        int rtn = salerService.updateSaler(saler);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存成功");
        }else{
            msg.setMsg("保存失败");
        }
        return msg;
    }
    @ApiOperation("查询列表案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="salerid",value="传递销售人员id"),
            @ApiImplicitParam(name="salerauditstate",value = "状态，0-不可用；1-正常")
    })
    @GetMapping("/list")
    public ListMessage<Saler> selectSaleList(Saler saler){
            ListMessage<Saler> listMessage = new ListMessage<>();
            List<Saler> list = salerService.selectSaler(saler);
            if(list!=null) {
                listMessage.setDatalist(list);
                listMessage.setCode(1);
            }else{
                listMessage.setCode(0);
                listMessage.setMsg("没有查询到数据");
            }
            return listMessage;
    }

    @ApiOperation("分页查询案例")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "deptname",value="传递字符串"),
//            @ApiImplicitParam(name = "deptstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行")}
    )
    @GetMapping("/page")
    public PageMessage<Saler> selectRoleByPage(Saler saler, Long pagenum, Long pagesize){
        Page<Saler> pagedata = salerService.selectByPage(saler,pagenum,pagesize);
        PageMessage<Saler> msg = new PageMessage<>();
        if(pagedata!=null) {
            msg.setCode(1);
            msg.setPagedata(pagedata);
        }else{
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("根据salerid查询一条saler信息的案例")
    @ApiImplicitParam("salerid")
    @GetMapping("/get/{salerid}")
    public PojoMessage<Saler> selectDepartmentById(@PathVariable("salerid") int salerid){
        PojoMessage<Saler> msg = new PojoMessage<>();
        Saler department = salerService.selectBySalerid(salerid);
        if(department!=null){
            msg.setCode(1);
            msg.setData(department);
        }else{
            msg.setCode(0);
            msg.setMsg("没有找到指定数据");
        }
        return msg;
    }
}
